﻿

Namespace YahooManaged.Geo.PlaceFinder.API


    Public Class PlaceFinderOptions
        Inherits ResultCountOptions

        ''' <summary>
        ''' Location setback in meters, intended to approximate a building location offset from the road center-line.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Offset As Integer = 15
        Public Property Culture As Culture = New Culture(Language.en, Country.US)

        Public Property CoordinatesOnly As Boolean = False
        Public Property NoWOEID As Boolean = False
        Public Property UsSpecificElements As Boolean = False
        Public Property IncludeNearestAirportCode As Boolean = False
        Public Property IncludeTelephoneAreaCode As Boolean = False
        Public Property IncludeDetailedStreetAttributes As Boolean = False
        Public Property IncludeTimezoneInfo As Boolean = False
        Public Property IncludeBoundingBox As Boolean = False
        Public Property IncludeNeighborhoodNames As Boolean = False
        Public Property IncludeCrossStreets As Boolean = False
        Public Property LimitResultsToCulture As Boolean = False
        ''' <summary>
        ''' Enables exact matches.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property QuickMode As Boolean = False
        ''' <summary>
        ''' Needs longitude/latitude value in LocationSearchOptions
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property ReverseGeoCoding As Boolean = False

    End Class


    Public MustInherit Class PlacesFinderQuery
        Friend MustOverride Function QueryString() As String
    End Class


    Public Class FreeFormQuery
        Inherits PlacesFinderQuery

        ''' <summary>
        ''' A location query string in free format.
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Location As String = String.Empty

        Friend Overrides Function QueryString() As String
            If Me.Location = String.Empty Then Throw New ArgumentException("The location is empty", "Location")
            Return "&location=" & Me.Location
        End Function
    End Class

    Public Class PointOfInterestQuery
        Inherits PlacesFinderQuery

        Public Property PointOfInterest As String = String.Empty

        Friend Overrides Function QueryString() As String
            If Me.PointOfInterest = String.Empty Then Throw New ArgumentException("The Point of Interest is empty", "PointOfInterest")
            Return "&name=" & Me.PointOfInterest
        End Function
    End Class


    Public Class WoeidQuery
        Inherits PlacesFinderQuery

        Public Property WOEID As Integer = 0

        Friend Overrides Function QueryString() As String
            If Me.WOEID = 0 Then Throw New ArgumentException("The WOEID is invalid", "WOEID")
            Return "&woeid=" & Me.WOEID.ToString
        End Function
    End Class




    Public Class ThreeLineAddressQuery
        Inherits PlacesFinderQuery

        Public Property StreetAddressOrIntersection As String = String.Empty
        Public Property CityOrStateOrZipCode As String = String.Empty
        Public Property PostalCode As String = String.Empty

        Friend Overrides Function QueryString() As String
            Dim params As String = String.Empty
            If Me.StreetAddressOrIntersection <> String.Empty Then
                params &= "&line1=" & Me.StreetAddressOrIntersection
            End If
            If Me.CityOrStateOrZipCode <> String.Empty Then
                params &= "&line2=" & Me.CityOrStateOrZipCode
            End If
            If Me.PostalCode <> String.Empty Then
                params &= "&line3=" & Me.PostalCode
            End If
            If params.Length = 0 Then Throw New ArgumentException("All Properties are empty", "")
            Return params
        End Function
    End Class


    Public Class GeneralAddressQuery
        Inherits PlacesFinderQuery

        ''' <summary>
        ''' House number
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property House As String = String.Empty
        Public Property Street As String = String.Empty
        ''' <summary>
        ''' Unit type such as Apartment(Apt) or Suite(Ste)
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property UnitType As String = String.Empty
        ''' <summary>
        ''' Unit decription i.e. appartment number
        ''' </summary>
        ''' <value></value>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Property Unit As String = String.Empty
        Public Property CrossStreet As String = String.Empty
        Public Property PostalCode As String = String.Empty
        Public Property Neighborhood As String = String.Empty
        Public Property City As String = String.Empty
        Public Property County As String = String.Empty
        Public Property State As String = String.Empty
        Public Property Country As String = String.Empty

        Friend Overrides Function QueryString() As String
            Dim sb As New Text.StringBuilder
            If Me.House <> String.Empty Then sb.Append("&house=" & Me.House)
            If Me.Street <> String.Empty Then sb.Append("&street=" & Me.Street)
            If Me.UnitType <> String.Empty Then sb.Append("&untittype=" & Me.UnitType)
            If Me.Unit <> String.Empty Then sb.Append("&unit=" & Me.Unit)
            If Me.CrossStreet <> String.Empty Then sb.Append("&xstreet=" & Me.CrossStreet)
            If Me.PostalCode <> String.Empty Then sb.Append("&postal=" & Me.PostalCode)
            If Me.Neighborhood <> String.Empty Then sb.Append("&level4=" & Me.Neighborhood)
            If Me.City <> String.Empty Then sb.Append("&level3=" & Me.City)
            If Me.County <> String.Empty Then sb.Append("&level2=" & Me.County)
            If Me.State <> String.Empty Then sb.Append("&level1=" & Me.State)
            If Me.Country <> String.Empty Then sb.Append("&level0=" & Me.Country)
            If sb.Length = 0 Then Throw New ArgumentException("All Properties are empty", "")
            Return sb.ToString
        End Function

    End Class



End Namespace